import 'package:bruno/bruno.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

import '../../../../data/models/doctor_list_res.dart';
import '../controllers/doctor_controller.dart';

class DoctorView extends GetView<DoctorController> {
  const DoctorView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Color(0xffF1F1F1),
        appBar: AppBar(
          elevation: 0,
          scrolledUnderElevation: 0,
          title: Container(
            height: 40.h,
            decoration: BoxDecoration(
              color: Color(0xffF1F1F1),
              borderRadius: BorderRadius.circular(20.r),
            ),
            child: Row(
              children: [
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: 12.w),
                  child: Icon(Icons.search, color: Colors.grey),
                ),
                Expanded(
                  child: TextField(
                    controller: controller.textController,
                    decoration: const InputDecoration(
                        hintText: "请输入医生",
                        border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                            borderRadius:
                                BorderRadius.all(Radius.circular(16)))),
                  ),
                )
              ],
            ),
          ),
        ),
        body: Obx(() {
        return  EasyRefresh(
            controller: controller.refreshController,
            header: const ClassicHeader(),
            footer: const ClassicFooter(),
            onLoad: controller.onLoad,
            onRefresh: controller.onRefresh,
            child: ListView.builder(
                itemCount: controller.list.length,
                itemBuilder: (context, index) {
                  return _buildItem(controller.list[index]);
                }),
          );
        }));
  }

  Widget _buildItem(DoctorModel model) {
    return Stack(
      children: [Container(
          color: Colors.white,
          padding: EdgeInsets.symmetric(horizontal: 16),
          margin: EdgeInsets.only(bottom: 2),
          child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  margin: EdgeInsets.only(top:4 ,right: 8),
                  child: CachedNetworkImage(
                    imageUrl: model.photo ?? '',
                    imageBuilder: (context, image) {
                      return CircleAvatar(
                        foregroundImage: image,
                        radius: 36,
                      );
                    },
                    placeholder: (context, url){
                      return Container(
                        decoration: BoxDecoration(
                            color: Color(0xffF1F1F1),
                            borderRadius: BorderRadius.circular(36)),
                      );
                    },
                  ),
                ),
                Expanded(child: Container(
                  padding: EdgeInsets.symmetric(vertical: 4),
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        children: [
                          Text("${model.nickName}",style: TextStyle(fontSize: 15.w,color: Color(0xff333333)),),
                          SizedBox(width: 4,),
                          Text("${model.title??''}",style: TextStyle(fontSize: 14.w,color: Color(0xff666666)),),
                          SizedBox(width: 4,),
                          Text("${model.dept??''}",style: TextStyle(fontSize: 14.w,color: Color(0xff666666)),)
                        ],
                      ),
                      SizedBox(height: 4,
                      ),
                      Text("${model.introduction}",
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(fontSize: 12.w,color: Color(0xff666666)),),
                      SizedBox(height: 4,
                      ),
                      Row(
                        children: [
                          Text("图文："),
                          Text("￥0（限时免费）",style: TextStyle(color: Colors.redAccent),),
                          SizedBox(width: 4,),

                        ],
                      ),
                      Row(
                        children: [

                          Text("电话："),
                          Text("￥0（限时免费）",style: TextStyle(color: Colors.redAccent),)
                        ],
                      )
                    ],
                  ),
                ))
              ])),
      Positioned(
          bottom: 9,
          right: 16,
          child: BrnSmallMainButton(
            title: '问医生',
            onTap: () {
              controller.postConsultation(model.userId??0,model);
            },
          ))
      ],
    );
  }
}
